CSharpTest.Net
EnableCount Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.BPlusTree Assembly > CSharpTest.Net.Collections Namespace > BPlusTree<TKey,TValue> Class : EnableCount Method

Glossary Item Box

Due to the cost of upkeep, this must be enable each time the object is created via a call to EnableCount() which itself must be done before any writer threads are active for it to be accurate. This requires that the entire tree be loaded (sequentially) in order to build the initial working count. Once completed, members like Add() and Remove() will keep the initial count accurate.

Syntax

Visual Basic (Declaration) 
Public Sub EnableCount() 
C# 
public void EnableCount()

Example

BPlusTree/BPlusTree.Test/ThreadedMassInsertTest.cs

C#Copy Code
mreStop.Reset();
using(TempFile temp = new TempFile())
{
    BPlusTree<Guid, TestInfo>.OptionsV2 options = new BPlusTree<Guid, TestInfo>.OptionsV2(
        PrimitiveSerializer.Guid, new TestInfoSerializer());
    options.CalcBTreeOrder(16, 24);
    options.CreateFile = CreatePolicy.Always;
    options.FileName = temp.TempPath;
    using (BPlusTree<Guid, TestInfo> tree = new BPlusTree<Guid, TestInfo>(options))
    {
        tree.EnableCount();
        var actions = new List<IAsyncResult>();
        var tests = new Action<BPlusTree<Guid, TestInfo>>[] 
        {
            DeleteStuff, UpdateStuff, AddStuff, AddRanges, BulkyInserts,
            FetchStuff, FetchStuff, FetchStuff, FetchStuff, FetchStuff
        };

        foreach (var t in tests)
            actions.Add(t.BeginInvoke(tree, null, null));

        do
        {
            Trace.TraceInformation("Dictionary.Count = {0}", tree.Count);
            Thread.Sleep(1000);
        } while (Debugger.IsAttached);

        mreStop.Set();
        for (int i = 0; i < actions.Count; i++)
        {
            tests[i].EndInvoke(actions[i]);
        }

        Trace.TraceInformation("Dictionary.Count = {0}", tree.Count);
    }
}
VB.NETCopy Code
mreStop.Reset()
Using temp As New TempFile()
    Dim options As New BPlusTree(Of Guid, TestInfo).OptionsV2(PrimitiveSerializer.Guid, New TestInfoSerializer())
    options.CalcBTreeOrder(16, 24)
    options.CreateFile = CreatePolicy.Always
    options.FileName = temp.TempPath
    Using tree As New BPlusTree(Of Guid, TestInfo)(options)
        tree.EnableCount()
        Dim actions As var = New List(Of IAsyncResult)()
        Dim tests As var = New Action(Of BPlusTree(Of Guid, TestInfo))() {DeleteStuff, UpdateStuff, AddStuff, AddRanges, BulkyInserts, FetchStuff, _
            FetchStuff, FetchStuff, FetchStuff, FetchStuff}

        For Each t As var In tests
            actions.Add(t.BeginInvoke(tree, Nothing, Nothing))
        Next

        Do
            Trace.TraceInformation("Dictionary.Count = {0}", tree.Count)
            Thread.Sleep(1000)
        Loop While Debugger.IsAttached

        mreStop.[Set]()
        Dim i As Integer = 0
        While i < actions.Count
            tests(i).EndInvoke(actions(i))
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
        End While

        Trace.TraceInformation("Dictionary.Count = {0}", tree.Count)
    End Using
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys